package com.nn.controller;

import com.nn.pojo.Rights;
import com.nn.service.RightsService;
import com.nn.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/rights")
public class RightsController {
    @Autowired
    private RightsService rightsService;

    /**
     * 需求:查询权限列表信息 只查询2级权限列表信息
     * url: /rights/getRightsList
     * 参数: 无
     * 返回值:SysResult对象(List集合)
     */
    @GetMapping("/getRightsList")
    public SysResult getRightsList() {
        List<Rights> rightsList = rightsService.getRightsList();
        return SysResult.success(rightsList);
    }

    /**
     * 需求:
     * url:http://localhost:8091/rights/getRightsListAll
     */
    @GetMapping("/getRightsListAll")
    public SysResult getRightsListAll() {
        List<Rights> rightsListAll = rightsService.getRightsListAll();
        return SysResult.success(rightsListAll);
    }

    /**
     * url:http.get("/rights/getThreeRightsIds",{params:{roleId: role.roleId}})
     */
    @GetMapping("/getThreeRightsIds")
    public SysResult getThreeRightsIds(Integer roleId) {
        List<Rights> rightsIds = rightsService.getThreeRightsIds(roleId);
        return SysResult.success(rightsIds);
    }
}
